package com.cfuture08.eweb4j.config;

import java.util.Iterator;
import java.util.List;

import com.cfuture08.eweb4j.cache.SingleBeanCache;
import com.cfuture08.eweb4j.config.bean.ConfigBean;
import com.cfuture08.eweb4j.config.bean.ConfigIOC;
import com.cfuture08.eweb4j.config.bean.ConfigMVC;
import com.cfuture08.eweb4j.config.bean.ConfigORM;
import com.cfuture08.eweb4j.config.bean.IOCXmlFiles;
import com.cfuture08.eweb4j.config.bean.MVCXmlFiles;
import com.cfuture08.eweb4j.config.bean.ORMXmlFiles;
import com.cfuture08.eweb4j.ioc.config.bean.IOCConfigBean;
import com.cfuture08.eweb4j.ioc.config.bean.Injection;
import com.cfuture08.eweb4j.jdbc.ConnectionManager;
import com.cfuture08.eweb4j.jdbc.sql.DBType;
import com.cfuture08.eweb4j.mvc.ValidatorConstant;
import com.cfuture08.eweb4j.mvc.config.bean.FormBean;
import com.cfuture08.eweb4j.mvc.config.bean.MVCConfigBean;
import com.cfuture08.eweb4j.mvc.config.bean.Param;
import com.cfuture08.eweb4j.mvc.config.bean.Result;
import com.cfuture08.eweb4j.mvc.config.bean.Validator;
import com.cfuture08.eweb4j.orm.config.bean.ORMConfigBean;
import com.cfuture08.eweb4j.orm.config.bean.Property;
import com.cfuture08.eweb4j.orm.dao.config.bean.DAOConfigBean;
import com.cfuture08.util.FileUtil;
import com.cfuture08.util.RegexList;

/**
 * Check EWeb4J framework startup configuration files. Also included the ORM,
 * IOC, MVC three components
 * 
 * @author cfuture.aw
 * @since v1.a.0
 * 
 */
public class CheckConfigBean {
	public static String check(ConfigBean cb) {
		String error = null;
		StringBuilder sb = new StringBuilder();

		if (!"true".equalsIgnoreCase(cb.getDebug())
				&& !"false".equalsIgnoreCase(cb.getDebug())
				&& !"1".equals(cb.getDebug()) && !"0".equals(cb.getDebug())) {
			sb.append("当前您填写的：( debug=").append(cb.getDebug()).append(
					" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
		}
		if (!"".equals(sb.toString())) {
			error = "\n<br /><b>" + ConfigConstant.XMLFILE_PATH + ":</b>\n"
					+ sb.toString();
		}

		return error;
	}

	/**
	 * Check mainly in the configuration file IOC parts
	 * 
	 * @param ioc
	 * @return
	 */
	public static String check(ConfigIOC ioc) {
		String error = null;
		StringBuilder sb = new StringBuilder();
		if (!"true".equalsIgnoreCase(ioc.getOpen())
				&& !"false".equalsIgnoreCase(ioc.getOpen())
				&& !"1".equals(ioc.getOpen()) && !"0".equals(ioc.getOpen())) {
			sb.append("当前您填写的：( open=").append(ioc.getOpen()).append(
					" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
		} else if ("true".equalsIgnoreCase(ioc.getOpen())
				|| "1".equals(ioc.getOpen())) {
			if (!"true".equalsIgnoreCase(ioc.getDebug())
					&& !"false".equalsIgnoreCase(ioc.getDebug())
					&& !"1".equals(ioc.getDebug())
					&& !"0".equals(ioc.getDebug())) {
				sb.append("当前您填写的：( debug=").append(ioc.getDebug()).append(
						" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
			}
			if (!FileUtil.isValidFileName(ioc.getLogFile())) {
				sb.append("当前您填写的：( logFile=").append(ioc.getLogFile()).append(
						" )是错误的！它要符合文件命名规范 ;").append("\n");
			}
		}

		if (!"".equals(sb.toString())) {
			error = "\n<br /><b>" + ConfigConstant.XMLFILE_PATH
					+ "[ioc]:</b>\n" + sb.toString();
		}

		return error;
	}

	public static String checkIOCXml(List<IOCXmlFiles> xmlFiles) {
		String error = null;
		StringBuilder sb = new StringBuilder();
		for (IOCXmlFiles xml : xmlFiles) {
			if (!FileUtil.isValidFileName(xml.getPath())) {
				sb.append("当前您填写的：( path=").append(xml.getPath()).append(
						" )是错误的！它要符合文件命名规范 ;").append("\n");
			}
		}

		if (!"".equals(sb.toString())) {
			error = "\n<br /><b>" + ConfigConstant.XMLFILE_PATH
					+ "[ioc][xmlFiles]:</b>\n" + sb.toString();
		}

		return error;
	}

	/**
	 * Check mainly in the configuration file ORM parts
	 * 
	 * @param orm
	 * @return
	 */
	public static String check(ConfigORM orm) {
		String error = null;
		StringBuilder sb = new StringBuilder();
		if (!"true".equalsIgnoreCase(orm.getOpen())
				&& !"false".equalsIgnoreCase(orm.getOpen())
				&& !"1".equals(orm.getOpen()) && !"0".equals(orm.getOpen())) {
			sb.append("当前您填写的：( open=").append(orm.getOpen()).append(
					" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
		} else if ("true".equalsIgnoreCase(orm.getOpen())
				|| "1".equals(orm.getOpen())) {
			if (!"true".equalsIgnoreCase(orm.getDebug())
					&& !"false".equalsIgnoreCase(orm.getDebug())
					&& !"1".equals(orm.getDebug())
					&& !"0".equals(orm.getDebug())) {
				sb.append("当前您填写的：( debug=").append(orm.getDebug()).append(
						" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
			}
			if (!FileUtil.isValidFileName(orm.getLogFile())) {
				sb.append("当前您填写的：( logFile=").append(orm.getLogFile()).append(
						" )是错误的！它要符合文件命名规范 ;").append("\n");
			}
			if (!FileUtil.isValidFileName(orm.getDbInfoXmlFile())) {
				sb.append("当前您填写的：( dbInfoXmlFile=").append(
						orm.getDbInfoXmlFile()).append(" )是错误的！它要符合文件命名规范 ;")
						.append("\n");
			}
		}
		if (!"".equals(sb.toString())) {
			error = "\n<br /><b>" + ConfigConstant.XMLFILE_PATH
					+ "[orm]:</b>\n" + sb.toString();
		}

		return error;
	}

	public static String checkORMXml(List<ORMXmlFiles> xmlFiles) {
		String error = null;
		StringBuilder sb = new StringBuilder();
		for (ORMXmlFiles xml : xmlFiles) {
			if (!FileUtil.isValidFileName(xml.getPath())) {
				sb.append("当前您填写的：( path=").append(xml.getPath()).append(
						" )是错误的！它要符合文件命名规范 ;").append("\n");
			}
		}

		if (!"".equals(sb.toString())) {
			error = "\n<br /><b>" + ConfigConstant.XMLFILE_PATH
					+ "[orm][xmlFiles]:</b>\n" + sb.toString();
		}

		return error;
	}

	/**
	 * Check mainly in the configuration file MVC parts
	 * 
	 * @param mvc
	 * @return
	 */
	public static String check(ConfigMVC mvc) {
		String error = null;
		StringBuilder sb = new StringBuilder();
		if (!"true".equalsIgnoreCase(mvc.getOpen())
				&& !"false".equalsIgnoreCase(mvc.getOpen())
				&& !"1".equals(mvc.getOpen()) && !"0".equals(mvc.getOpen())) {
			sb.append("当前您填写的：( open=").append(mvc.getOpen()).append(
					" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
		} else if ("true".equalsIgnoreCase(mvc.getOpen())
				|| "1".equals(mvc.getOpen())) {
			if (!"true".equalsIgnoreCase(mvc.getDebug())
					&& !"false".equalsIgnoreCase(mvc.getDebug())
					&& !"1".equals(mvc.getDebug())
					&& !"0".equals(mvc.getDebug())) {
				sb.append("当前您填写的：( debug=").append(mvc.getDebug()).append(
						" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
			}
			if (!FileUtil.isValidFileName(mvc.getLogFile())) {
				sb.append("当前您填写的：( logFile=").append(mvc.getLogFile()).append(
						" )是错误的！它要符合文件命名规范 ;").append("\n");
			}
		}
		if (!"".equals(sb.toString())) {
			error = "\n<br /><b>" + ConfigConstant.XMLFILE_PATH
					+ "[mvc]:</b>\n" + sb.toString();
		}

		return error;
	}

	public static String check(List<MVCXmlFiles> xmlFiles) {
		String error = null;
		StringBuilder sb = new StringBuilder();
		for (MVCXmlFiles xml : xmlFiles) {
			if (!FileUtil.isValidFileName(xml.getPath())) {
				sb.append("当前您填写的：( path=").append(xml.getPath()).append(
						" )是错误的！它要符合文件命名规范 ;").append("\n");
			}
		}

		if (!"".equals(sb.toString())) {
			error = "\n<br /><b>" + ConfigConstant.XMLFILE_PATH
					+ "[mvc][xmlFiles]:</b>\n" + sb.toString();
		}

		return error;
	}

	/**
	 * Check the IOC independent components configuration files
	 * 
	 * @param ioc
	 * @return
	 */
	public static String check(IOCConfigBean ioc, String xmlFile) {
		String error = null;
		ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class);
		if ("true".equalsIgnoreCase(cb.getIoc().getOpen())
				|| "1".equals(cb.getIoc().getOpen())) {
			StringBuilder sb = new StringBuilder();
			if (!"prototype".equalsIgnoreCase(ioc.getScope())
					&& !"singleton".equalsIgnoreCase(ioc.getScope())
					&& !"".equals(ioc.getScope())) {
				sb.append("当前您填写的：( scope=").append(ioc.getScope()).append(
						" )是错误的！它只能填写为：prototype|singleton 中的一种 ;")
						.append("\n");
			}

			if (!"".equals(sb.toString())) {
				error = "\n<br /><b>" + xmlFile + ":[bean id=" + ioc.getId()
						+ "]</b>\n" + sb.toString();
			}
		}

		return error;
	}

	/**
	 * Check the IOC component Inject part configuration
	 * 
	 * @param inject
	 * @param iocList
	 * @return
	 */
	public static String check(List<Injection> inject,
			List<IOCConfigBean> iocList, String beanID, String xmlFile) {
		String error = null;
		ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class);
		if ("true".equalsIgnoreCase(cb.getIoc().getOpen())
				|| "1".equals(cb.getIoc().getOpen())) {
			StringBuilder sb = new StringBuilder();
			for (Injection inj : inject) {
				if (inj.getRef() != null && !"".equals(inj.getRef())) {
					boolean flag = false;
					for (IOCConfigBean iocBean : iocList) {
						if (!iocBean.getId().equals(inj.getRef())) {
							flag = true;
						} else {
							flag = false;
						}
					}
					if (flag) {
						sb.append("当前您填写的 :( ref=").append(inj.getRef())
								.append(" )是错误的！它必须是本文件中某个bean的id值 ;\n");
					}
				}
				if (!"".equals(inj.getType())) {
					if (!"int".equalsIgnoreCase(inj.getType())
							&& !"String".equalsIgnoreCase(inj.getType())
							&& !"boolean".equalsIgnoreCase(inj.getType())
							&& !"long".equalsIgnoreCase(inj.getType())
							&& !"double".equalsIgnoreCase(inj.getType())
							&& !"float".equalsIgnoreCase(inj.getType())) {
						sb
								.append("当前您填写的：( type=")
								.append(inj.getType())
								.append(
										" )是错误的！它只能填写为：int|String|long|float|boolean|double 中的一种 ;")
								.append("\n");
					}
				}
				if ("int".equalsIgnoreCase(inj.getType())) {
					if (!inj.getValue().matches(RegexList.integer_regexp)) {
						sb.append("当前您填写的：( value=").append(inj.getValue())
								.append(" )是错误的！它必须是整数！ ;").append("\n");
					}
				}

			}

			if (!"".equals(sb.toString())) {
				error = "\n<br /><b>" + xmlFile + "[bean id=" + beanID
						+ "][inject]:</b>\n" + sb.toString();
			}
		}
		return error;
	}

	/**
	 * Check the IOC component DBInfo part configuration
	 * 
	 * @param dcb
	 * @return
	 */
	public static String check(DAOConfigBean dcb) {
		String error = null;
		ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class);
		if ("true".equals(cb.getOrm().getOpen())
				|| "1".equals(cb.getOrm().getOpen())) {
			StringBuilder sb = new StringBuilder();
			if (!DBType.MYSQL_DB.equalsIgnoreCase(dcb.getDataBaseType())
					&& !DBType.MSSQL_DB.equalsIgnoreCase(dcb.getDataBaseType())
					&& !DBType.ORACLE_DB
							.equalsIgnoreCase(dcb.getDataBaseType())) {
				sb.append("当前您填写的: ( dataBaseType=").append(
						dcb.getDataBaseType()).append(" )是错误的！它必须为：").append(
						DBType.MYSQL_DB).append("|").append(DBType.MSSQL_DB)
						.append("|").append(DBType.ORACLE_DB).append(
								"中的其中一个,忽略大小写 ;").append("\n");
			}
			if (!"".equals(dcb.getJdbcUtil())) {
				if (!ConnectionManager.class.getName()
						.equals(dcb.getJdbcUtil())) {
					sb.append("当前您填写的: ( jdbcUtil=").append(dcb.getJdbcUtil())
							.append(" )是错误的！它必须为： ").append(
									ConnectionManager.class.getName()).append(
									" ;\n");
				}
			}
			if (!"com.mysql.jdbc.Driver".equals(dcb.getDriverClass())) {
				sb.append("当前您填写的 :( driver=").append(dcb.getDriverClass())
						.append(" )是错误的！它必须为：").append(
								"com.mysql.jdbc.Driver！目前仅支持mysql ;\n");
			}

			if (!"true".equalsIgnoreCase(dcb.getAutoCommitOnClose())
					&& !"false".equalsIgnoreCase(dcb.getAutoCommitOnClose())
					&& !"1".equals(dcb.getAutoCommitOnClose())
					&& !"0".equals(dcb.getAutoCommitOnClose())) {
				sb.append("当前您填写的 ：( autoCommitOnClose=").append(
						dcb.getAutoCommitOnClose()).append(
						" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
			}
			if (!"true".equalsIgnoreCase(dcb.getTestConnectionOnCheckout())
					&& !"false".equalsIgnoreCase(dcb
							.getTestConnectionOnCheckout())
					&& !"1".equals(dcb.getTestConnectionOnCheckout())
					&& !"0".equals(dcb.getTestConnectionOnCheckout())) {
				sb.append("当前您填写的：( testConnectionOnCheckout=").append(
						dcb.getTestConnectionOnCheckout()).append(
						" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
			}
			if (!"true".equalsIgnoreCase(dcb.getTestConnectionOnCheckin())
					&& !"false".equalsIgnoreCase(dcb
							.getTestConnectionOnCheckin())
					&& !"1".equals(dcb.getTestConnectionOnCheckin())
					&& !"0".equals(dcb.getTestConnectionOnCheckin())) {
				sb.append("当前您填写的：( testConnectionOnCheckin=").append(
						dcb.getTestConnectionOnCheckin()).append(
						" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
			}
			if (!"true".equalsIgnoreCase(dcb.getBreakAfterAcquireFailure())
					&& !"false".equalsIgnoreCase(dcb
							.getBreakAfterAcquireFailure())
					&& !"1".equals(dcb.getBreakAfterAcquireFailure())
					&& !"0".equals(dcb.getBreakAfterAcquireFailure())) {
				sb.append("当前您填写的：( breakAfterAcquireFailure=").append(
						dcb.getBreakAfterAcquireFailure()).append(
						" )是错误的！它只能填写为：true|false|1|0 中的一种 ;").append("\n");
			}

			if (!dcb.getInitialPoolSize().matches(RegexList.integer_regexp)) {
				sb.append("当前您填写的：( initialPoolSize=").append(
						dcb.getInitialPoolSize()).append(" )是错误的！它必须是整数！ ;")
						.append("\n");
			}
			if (!dcb.getMaxPoolSize().matches(RegexList.integer_regexp)) {
				sb.append("当前您填写的：( maxPoolSize=").append(dcb.getMaxPoolSize())
						.append(" )是错误的！它必须是整数！ ;").append("\n");
			}
			if (!dcb.getMinPoolSize().matches(RegexList.integer_regexp)) {
				sb.append("当前您填写的：( minPoolSize=").append(dcb.getMinPoolSize())
						.append(" )是错误的！它必须是整数！ ;").append("\n");
			}
			if (!dcb.getAcquireIncrement().matches(RegexList.integer_regexp)) {
				sb.append("当前您填写的：( acquireIncrement=").append(
						dcb.getAcquireIncrement()).append(" )是错误的！它必须是整数！ ;")
						.append("\n");
			}
			if (!dcb.getIdleConnectionTestPeriod().matches(
					RegexList.integer_regexp)) {
				sb.append("当前您填写的：( idleConnectionTestPeriod=").append(
						dcb.getIdleConnectionTestPeriod()).append(
						" )是错误的！它必须是整数！ ;").append("\n");
			}
			if (!dcb.getMaxIdleTime().matches(RegexList.integer_regexp)) {
				sb.append("当前您填写的：( maxIdleTime=").append(dcb.getMaxIdleTime())
						.append(" )是错误的！它必须是整数！ ;").append("\n");
			}
			if (!dcb.getAcquireRetryAttempts()
					.matches(RegexList.integer_regexp)) {
				sb.append("当前您填写的：( acquireRetryAttempts=").append(
						dcb.getAcquireRetryAttempts()).append(
						" )是错误的！它必须是整数！ ;").append("\n");
			}
			if (!dcb.getAcquireRetryDelay().matches(RegexList.integer_regexp)) {
				sb.append("当前您填写的：( acquireRetryDelay=").append(
						dcb.getAcquireRetryDelay()).append(" )是错误的！它必须是整数！ ;")
						.append("\n");
			}

			if (!"".equals(sb.toString())) {
				error = "\n<br /><b>" + cb.getOrm().getDbInfoXmlFile()
						+ ":</b>\n" + sb.toString();
			}
		}

		return error;
	}

	/**
	 * Check the ORM independent components configuration files
	 * 
	 * @param orm
	 * @return
	 */
	public static String check(ORMConfigBean orm, String xmlFile) {
		String error = null;
		ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class);
		if ("true".equalsIgnoreCase(cb.getOrm().getOpen())
				|| "1".equals(cb.getOrm().getOpen())) {
			StringBuilder sb = new StringBuilder();
			if (!"".equals(orm.getClazz())) {
				try {
					if (Class.forName(orm.getClazz()) == null) {
						sb.append("当前您填写的( class=").append(orm.getClazz())
								.append(" )是错误的！它必须是一个有效的类 ;\n");
					}
				} catch (ClassNotFoundException e) {
					sb.append("当前您填写的( class=").append(orm.getClazz()).append(
							" )是错误的！它必须是一个有效的类 ;\n");
				}
			}

			if (!"".equals(sb.toString())) {
				error = "\n<br /><b>" + xmlFile + ":[bean name=]" + orm.getId()
						+ "]</b>\n" + sb.toString();
			}
		}

		return error;
	}

	/**
	 * Check the Property part of ORM components configuration
	 * 
	 * @param pList
	 * @param ormList
	 * @return
	 */
	public static String checkORM(List<Property> pList,
			List<ORMConfigBean> ormList, String beanID, String xmlFile) {
		String error = null;
		ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class);
		if ("true".equalsIgnoreCase(cb.getOrm().getOpen())
				|| "1".equals(cb.getOrm().getOpen())) {
			StringBuilder sb = new StringBuilder();
			for (Property p : pList) {
				if (p.getRelBean() != null && !"".equals(p.getRelBean())) {
					boolean flag = false;
					for (ORMConfigBean ormBean : ormList) {
						if (!ormBean.getId().equals(p.getRelBean())) {
							flag = true;
						} else {
							flag = false;
							break;// 如果找到了就不必继续遍历了
						}
					}
					if (flag) {
						sb.append("当前您填写的 : ( relBean=").append(p.getRelBean())
								.append(" )是错误的！它必须是本文件中某个bean的id值 ;\n");
					}
				}
			}

			if (!"".equals(sb.toString())) {
				error = "\n<br /><b>" + xmlFile + "[bean id=" + beanID
						+ "][property]:</b>\n" + sb.toString();
			}
		}

		return error;
	}

	/**
	 * Check the MVC independent components configuration files
	 * 
	 * @param mvc
	 * @return
	 */
	public static String check(MVCConfigBean mvc, String xmlFile) {
		String error = null;
		ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class);
		if ("true".equalsIgnoreCase(cb.getMvc().getOpen())
				|| "1".equals(cb.getMvc().getOpen())) {
			StringBuilder sb = new StringBuilder();
			if (!"".equals(mvc.getClazz())) {
				try {
					if (Class.forName(mvc.getClazz()) == null) {
						sb.append("当前您填写的( class=").append(mvc.getClazz())
								.append(" )是错误的！它必须是一个有效的类 ;\n");
					}
				} catch (ClassNotFoundException e) {
					sb.append("当前您填写的( class=").append(mvc.getClazz()).append(
							" )是错误的！它必须是一个有效的类 ;\n");
				}
			}

			if (!"".equals(sb.toString())) {
				error = "\n<br /><b>" + xmlFile + ":[bean name="
						+ mvc.getName() + "]</b>\n" + sb.toString();
			}
		}

		return error;
	}

	/**
	 * Check the Result part of MVC components configuration
	 * 
	 * @param rList
	 * @return
	 */
	public static String checkMVC(List<Result> rList, String beanID,
			String xmlFile) {
		String error = null;
		ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class);
		if ("true".equalsIgnoreCase(cb.getMvc().getOpen())
				|| "1".equals(cb.getMvc().getOpen())) {
			StringBuilder sb = new StringBuilder();
			for (Iterator<Result> it = rList.iterator(); it.hasNext();) {
				Result r = it.next();
				if (!"forward".equalsIgnoreCase(r.getType())
						&& !"redirect".equalsIgnoreCase(r.getType())
						&& !"ajax".equalsIgnoreCase(r.getType())
						&& !"".equals(r.getType())) {
					sb.append("当前您填写的：( type=").append(r.getType()).append(
							" )是错误的！它只能填写为：success|error|ajax|留空  中的一种 ;")
							.append("\n");
				}
			}

			if (!"".equals(sb.toString())) {
				error = "\n<br /><b>" + xmlFile + "[bean name=" + beanID
						+ "][result]:</b>\n" + sb.toString();
			}
		}

		return error;
	}

	/**
	 * Check the FormBean part of MVC components configuration
	 * 
	 * @param rList
	 * @return
	 */
	public static String checkFormBean(List<FormBean> fList, String beanID,
			String xmlFile) {
		String error = null;
		ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class);
		if ("true".equalsIgnoreCase(cb.getMvc().getOpen())
				|| "1".equals(cb.getMvc().getOpen())) {
			if (fList != null && !fList.isEmpty()) {
				StringBuilder sb = new StringBuilder();
				for (Iterator<FormBean> it = fList.iterator(); it.hasNext();) {
					FormBean f = it.next();
					if (!"".equals(f.getClazz())) {
						try {
							if (Class.forName(f.getClazz()) == null) {
								sb.append("当前您填写的( class=")
										.append(f.getClazz()).append(
												" )是错误的！它必须是一个有效的类 ;\n");
							}
						} catch (ClassNotFoundException e) {
							sb.append("当前您填写的( class=").append(f.getClazz())
									.append(" )是错误的！它必须是一个有效的类 ;\n");
						}
					}
				}

				if (!"".equals(sb.toString())) {
					error = "\n<br /><b>" + xmlFile + "[bean name=" + beanID
							+ "][formBean]:</b>\n" + sb.toString();
				}
			}
		}
		return error;
	}

	/**
	 * Check the Validator part of MVC components configuration
	 * 
	 * @param rList
	 * @return
	 */
	public static String checkValidator(List<Validator> vList, String beanID,
			String xmlFile) {
		String error = null;
		ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class);
		if ("true".equals(cb.getMvc().getOpen())
				|| "1".equals(cb.getMvc().getOpen())) {
			if (vList != null && !vList.isEmpty()) {
				StringBuilder sb = new StringBuilder();
				for (Iterator<Validator> it = vList.iterator(); it.hasNext();) {
					Validator v = it.next();
					if (!"".equals(v.getName())) {
						if (!ValidatorConstant.REQUIRED_VAL.equalsIgnoreCase(v
								.getName())
								&& !ValidatorConstant.INT_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.EMAIL_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.DATE_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.URL_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.ID_CARD_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.ZIP_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.PHONE_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.QQ_VAL.equalsIgnoreCase(v
										.getName())
								&& !ValidatorConstant.IP_VAL
										.equals(v.getName())
								&& !ValidatorConstant.CHINESE_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.STRING_LENGTH_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.INT_SIZE_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.FORBID_VAL
										.equalsIgnoreCase(v.getName())
								&& !ValidatorConstant.ENUM_VAL
										.equalsIgnoreCase(v.getName())) {
							sb.append("当前您填写的：( name=").append(v.getName());
							sb.append(" )是错误的！它只能填写为：required|int|");
							sb.append("email|date|url|idCard|zip|phone|qq|ip|");
							sb
									.append("chinese|length|size|forbid|enum|留空  中的一种 ,忽略大小写 ;\n");
						} else if (ValidatorConstant.INT_SIZE_VAL
								.equalsIgnoreCase(v.getName())) {
							int minSize = 0;
							for (Param p : v.getParam()) {
								if (ValidatorConstant.MIN_SIZE_PARAM
										.equalsIgnoreCase(p.getName())) {
									if (!(p.getValue()
											.matches(RegexList.integer_regexp))) {
										sb.append("<param>当前您填写的：( value=")
												.append(p.getValue());
										sb.append(" )是错误的！它应该填写为数字");

									} else {
										minSize = Integer
												.parseInt(p.getValue());
									}
								} else if (ValidatorConstant.MAX_SIZE_PARAM
										.equalsIgnoreCase(p.getName())) {
									if (!(p.getValue()
											.matches(RegexList.integer_regexp))) {
										sb.append("<param>当前您填写的：( value=")
												.append(p.getValue());
										sb.append(" )是错误的！它应该填写为数字");
									} else {
										int maxSize = Integer.parseInt(p
												.getValue());
										if (minSize > maxSize) {
											sb.append("<param>当前您填写的：( value=")
													.append(p.getValue());
											sb.append(" )是错误的！它不能比minSize的值");
											sb.append(minSize).append("更小");
										}
									}
								} else {
									sb.append("<param>当前您填写的：( name=").append(
											p.getName());
									sb.append(" )是错误的！它只能填写为：minSize|maxSize|");
									sb.append("中的一种 ,忽略大小写 ;\n");
								}
							}
						} else if (ValidatorConstant.STRING_LENGTH_VAL
								.equalsIgnoreCase(v.getName())) {
							int minLength = 0;
							for (Param p : v.getParam()) {
								if (ValidatorConstant.MIN_LENGTH_PARAM
										.equalsIgnoreCase(p.getName())) {
									if (!(p.getValue()
											.matches(RegexList.integer_regexp))) {
										sb.append("<param>当前您填写的：( value=")
												.append(p.getValue());
										sb.append(" )是错误的！它应该填写为数字");
									} else {
										minLength = Integer.parseInt(p
												.getValue());
									}
								} else if (ValidatorConstant.MAX_LENGTH_PARAM
										.equalsIgnoreCase(p.getName())) {
									if (!(p.getValue()
											.matches(RegexList.integer_regexp))) {
										sb.append("<param>当前您填写的：( value=")
												.append(p.getValue());
										sb.append(" )是错误的！它应该填写为数字");
									} else {
										int maxLength = Integer.parseInt(p
												.getValue());
										if (minLength > maxLength) {
											sb.append("<param>当前您填写的：( value=")
													.append(p.getValue());
											sb.append(" )是错误的！它不能比minLength的值");
											sb.append(minLength).append("更小");
										}
									}
								} else {
									sb.append("<param>当前您填写的：( name=").append(
											p.getName());
									sb
											.append(" )是错误的！它只能填写为：minLength|maxLength|");
									sb.append("中的一种 ,忽略大小写 ;\n");
								}
							}
						} else if (ValidatorConstant.FORBID_VAL
								.equalsIgnoreCase(v.getName())) {
							for (Param p : v.getParam()) {
								if (!ValidatorConstant.FORBID_WORD_PARAM
										.equalsIgnoreCase(p.getName())) {
									sb.append("<param>当前您填写的：( name=").append(
											p.getName());
									sb.append(" )是错误的！它只能填写为：forbidWord|");
									sb.append("忽略大小写 ;\n");
								}
							}
						} else if (ValidatorConstant.ENUM_VAL
								.equalsIgnoreCase(v.getName())) {
							for (Param p : v.getParam()) {
								if (!ValidatorConstant.ENUM_WORD_PARAM
										.equalsIgnoreCase(p.getName())) {
									sb.append("<param>当前您填写的：( name=").append(
											p.getName());
									sb.append(" )是错误的！它只能填写为：enumWord|");
									sb.append("忽略大小写 ;\n");
								}
							}
						}
					}

					if (!"".equals(v.getClazz())) {
						try {
							if (Class.forName(v.getClazz()) == null) {
								sb.append("当前您填写的( class=")
										.append(v.getClazz()).append(
												" )是错误的！它必须是一个有效的类 ;\n");
							}
						} catch (ClassNotFoundException e) {
							sb.append("当前您填写的( class=").append(v.getClazz())
									.append(" )是错误的！它必须是一个有效的类 ;\n");
						}
					}
				}

				if (!"".equals(sb.toString())) {
					error = "\n<br /><b>" + xmlFile + "[bean name=" + beanID
							+ "][validator]:</b>\n" + sb.toString();
				}
			}
		}

		return error;
	}

}
